<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<style>
.detailTable input[type="text"]{
	width: 210px;
}
</style>
<div class="easyui-layout" style="width:100%;height:100%;" fit="true">
    <div data-options="region:'center',split:true" style="width: 100%;height: 100%">
		<table id="userGrid"></table>
	</div>
    <div data-options="region:'north',title:'',split:true" style="width: 100%;height: 200px">
		<form id="userInfoForm" method="post" >
			<input type="hidden" id="salesmanId" name="salesmanId" data-options="required:true">        
			<input type="hidden" id="userName" name="userName"><!-- 用户名：salesmanName -->
			<input type="hidden" id="email" name="email"><!-- 电子邮箱： -->
			<input type="hidden" id="qq" name="qq"><!-- QQ： -->
			<input type="hidden" id="address" name="address"><!-- 地址：address -->
			<input type="hidden" id="mobilePhone" name="mobilePhone"><!-- 手机号码： -->
			<input type="hidden" id="telePhone" name="telePhone"><!-- 座机： -->
			<input type="hidden" id="postCode" name="postCode"><!-- 邮编： -->
			<input type="hidden" id="notes" name="notes"><!-- 备注： -->
			<input type="hidden" id="linkMan" name="linkMan"><!-- 联系人： -->
			<input type="hidden" id="extendCode" name="extendCode"><!-- 企业编码： -->
			<input type="hidden" id="userType" name="userType" value="3"   > 
             
			<table class="detailTable"> 
    	 	<tr>
                <th>登录名:</th> 
                <td><input class="easyui-validatebox " id="loginName" name="loginName" data-options="required:true"></td>
            </tr>
            <tr>
                <th>密码:</th>
                <td><input class="easyui-validatebox " type="password" id="loginPwd" name="loginPwd" data-options="required:true"></td>
            </tr>
            <tr>
                <th>再次输入密码:</th>
                <td><input class="easyui-validatebox " type="password" id="loginPwd1" name="loginPwd1" data-options="required:true" validType="same['loginPwd']"></td>
            </tr>
			<tr>
			   
				<td align="center" colspan="2" > 
					<input type="button" onclick="submitForm()" class="button" value="提交" >
				<!-- 	<input type="button" onclick="pms.resetForm('userInfoForm')" class="button" value="重置" >    --> 
				</td>
			</tr>
		</table>
		</form>
    </div>
</div>  
<script>
var tbl;
$(function(){
	initList();
})

function initList(){
	
	tbl = $('#userGrid').pDataGrid({
		 columns:[[
				  {field:'loginName',title:'登录名称',width:'200',sortable:true},
				  {field:'userName',title:'用户名称',width:'200',sortable:true},
				  {field:'isValid',title:'用户状态',width:'60',sortable:true,align:'center',
					  formatter:function(value,row){
						  var str = '';
							switch(value){
							case 0:
								str = '刚注册';
								break;
							case 1:
								str = '已审核';
								break;
							case 2:
								str = '被锁定';
								break;
							default:
								str = '刚注册';
								break;
							}
							return str;
						}  
				  }
				  ]
			  ],
			  url:'<c:url value="/salesman/showEmBSalesmanDetail.do"/>',
		    pagination:false,
		    queryParams:{
		    	"salesmanId":<%=request.getParameter("code")%>
		    },
		    completeCallback:function(data){
		    	var emBSalesman = data.data.emBSalesman;
				if(data.resultCode == "100"){
					alertError(data.result);
				}else{
					demoSalesmanDetail(emBSalesman);
				} 
				
			}
	}); 
	
}
//$(function(){
//	var salesmanId="<%=request.getParameter("code")%>";
//	var param = {"salesmanId":salesmanId};
//		$.pmsAjax({
//		url:'<c:url value="/emBSalesman/showemBSalesmanDetail.do"/>',
//		data:param,
//		success:function(data){
//			var emBSalesman = data.data.emBSalesman;	
//			//console.log(emBSalesman);
//			if(data.code=="200"){
//				demoSalesmanDetail(emBSalesman);
//			}else{
//				alertError(data.result);
//			}	
//		}
//	});
//})
//返回数据load到from
function demoSalesmanDetail(emBSalesman){
	$('#userInfoForm').form('load',{
		salesmanId:emBSalesman.salesmanId,
		userName:emBSalesman.salesmanName,
		qq:emBSalesman.qq,
		address:emBSalesman.salesmanNative,
		mobilePhone:emBSalesman.mobile,
		telePhone:emBSalesman.phone,
		postCode:emBSalesman.zip,
		notes:emBSalesman.remark,
		extendCode:emBSalesman.salesmanNo
	});
}
function submitForm(){
	$('#userInfoForm').form('submit', {
		url:'<c:url value="/salesman/addSalesmanUser.do"/>', 
	    onSubmit: function(param){
	    	if(!$("#userInfoForm").form('validate')){
	    		return false;
	    	}
	    	//alert(url);
	    	//时间对比
	    }, 
	    success:function(data){
		    var ret = eval("("+data+")");
		    console.log(ret);
		   // alert(ret.code);
	     	if(ret.code=='200'){
	     		alertShow("新增成功");
	     		salesmansTable.refresh();
	     		$("#w_adduser").dialog('close');
		    }else{
		    	alertError(ret.result);
			}
	    }
	});
}


</script>
